using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewAndong.Entity;
using NewAndong.Model;
using Leeder.Service;
using Leeder.Repository;

namespace NewAndong.Service
{
    /// <summary>
    /// 
    /// </summary>
   public class SystemDeviceMonitorService : BaseService<SystemDeviceMonitorModel>
   {
        /// <summary>
        /// 关联实体类型
        /// </summary>
        protected override Type RefEntityType { get { return typeof(SystemDeviceMonitorEntity); } }

        /// <summary>
        /// 根据条件获取数据总量
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public int GetQueueCountByWhere(string where)
        {
            return RF<SystemDeviceMonitorEntity>.SqlQueryable("SELECT  * FROM LA_SystemDeviceMonitor " + where).Count();
        }

        /// <summary>
        /// 根据条件获取指定分页指定数量的记录
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">单页数据数量</param>
        /// <returns></returns>
        public List<SystemDeviceMonitorModel> GetQueueByPage(string where, int pageIndex, int pageSize)
        {
            if (pageIndex < 1)
                return null;
            pageIndex = (pageIndex - 1) * pageSize;
            return RF<SystemDeviceMonitorEntity>.SqlQueryable("SELECT  * FROM LA_SystemDeviceMonitor " + where + " ORDER BY ExceptionDate DESC OFFSET " + pageIndex + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY ").Select(s => new SystemDeviceMonitorModel
            {
                ID = s.ID,
                DeviceId = s.DeviceId,
                DeviceName = s.DeviceName,
                ExceptionDescription = s.ExceptionDescription,
                ExceptionDate = s.ExceptionDate,
                IsPhantom = s.IsPhantom,
            }).ToList();
        }
    }
}